#!/usr/bin/python
# -*- coding: utf-8 -*-
from maya import OpenMaya as om
import maya.OpenMayaAnim as oma
class Matching():
    #get dag path form a name or full name
    def getDagByName(self,name):
        it = om.MItDag()
        while not it.isDone():
            d = om.MDagPath()
            it.getPath(d)
            if d.partialPathName() == name:
                return d
            elif d.fullPathName() == name:
                return d
            it.next()
    
    #get MObject  form a name or full name
    def getMObjByName(self,name):
        if "|" in name:
            it = om.MItDag()
            while not it.isDone():
                d = om.MDagPath()
                it.getPath(d)
                if d.partialPathName() == name:
                    return it.currentItem()
                elif d.fullPathName() == name:
                    return it.currentItem()
                it.next()
        else:
            itDnos = om.MItDependencyNodes()
            while not itDnos.isDone():
                mobj = itDnos.thisNode()
                deNode = om.MFnDependencyNode(mobj)
                if deNode.name()==name:
                    return mobj
                itDnos.next()

SearchByName = Matching()